from collections import namedtuple
from random import triangular
from typing import List
import string


class Solution:
    def countDaysTogether(self, arriveAlice: str, leaveAlice: str, 
                          arriveBob: str, leaveBob: str) -> int:
        days = [-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        dates = [arriveAlice, leaveAlice, arriveBob, leaveBob]
        dates = [list(map(int, s.split('-'))) for s in dates]
        
        def comp(dates1, dates2):  #<
            if dates1[0] < dates2[0]:
                return 1
            if dates1[0] > dates2[0]:
                return 0
            return dates1[1] < dates2[1]

        if comp(dates[1], dates[2]) or comp(dates[3], dates[0]):
            return 0
        
        start = dates[2] if comp(dates[0], dates[2]) else dates[0]
        end   = dates[1] if comp(dates[1], dates[3]) else dates[3]
        
        res = 0
        if start[0] != end[0]:
            for i in range(start[0], end[0]):
                res += days[i]
            res -= (start[1]-1)
            res += end[1]
        else:
            res += (end[1]-start[1]+1)
              
        return res
    
    
    def matchPlayersAndTrainers(self, players: List[int], trainers: List[int]) -> int:
        m = len(players)
        n = len(trainers)
        
        players.sort()
        trainers.sort()
        
        res = 0
        i, j = 0, 0
        while i < m and j < n:
            if players[i] > trainers[j]:
                j += 1
            else:
                res += 1
                i += 1
                j += 1
        
        return res
    
    
    def smallestSubarrays(self, nums: List[int]) -> List[int]:
        n = len(nums)
        
        res = [0] * n
        
        for i in range(n):
            val = nums[i]
            length = 1
            for j in range(i+1, n):
                if val | nums[j] > val:
                    val = val | nums[j]
                    length = j - i + 1
            res[i] = length
            
        return res


if __name__ == "__main__":
    arriveAlice = "08-15"
    leaveAlice = "08-18"
    arriveBob = "08-16"
    leaveBob = "08-19"
    
    arriveAlice = "10-01"
    leaveAlice = "10-31"
    arriveBob = "11-01"
    leaveBob = "12-31"
    
    so = Solution()
    print(so.countDaysTogether(arriveAlice, leaveAlice, arriveBob, leaveBob))
    print(arriveAlice.split('_'))
    
    print(len("sadhbsAHbshSUCBAVSNhjShzzUizj,,s,SL.oOJSHhsaucbnUsbvdiuifh,SUvbaosduifghdondfiudghvdsuhdrfjnbgdbvbdjbsdkfjdghsvj.,asdusfgdasufashfuasdhad8wefjdvibn,.asvasdqwUWJOA"))

    def random_string_generator(size, chars):
        return ''.join(random.choice(chars) for _ in range(size))

    allowed_chars = string.ascii_letters + '.,'

    print(random_string_generator(1000, allowed_chars))
